package com.psytech.app.task.entity.implementation;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.validator.NotNull;

/**
 * The persistent class for the task database table.
 */
@Entity
@Table(name = "task")
public class Task implements Serializable, STMEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5322149514091696560L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	private String uid;

	@Lob()
	private String description;

	@NotNull
	private String name;

	@NotNull
	private String priority;

	private Date expectedEndDate;

	private Date expectedStartDate;

	@NotNull
	private String status;

	// bi-directional many-to-one association to User
	@ManyToOne(targetEntity = User.class)
	@JoinColumn(name = "creatorId")
	private User creator;

	// bi-directional many-to-many association to User
	@ManyToMany
	@JoinTable(name = "todo", joinColumns = { @JoinColumn(name = "idTask") }, inverseJoinColumns = { @JoinColumn(name = "idUser") })
	private List<User> users;

	@OneToMany(mappedBy = "task", targetEntity = Comment.class, cascade = CascadeType.REMOVE)
	private List<Comment> comments;

	@Override
	public Integer getId() {
		return this.id;
	}

	@Override
	public void setId(final Integer id) {
		this.id = id;
	}

	/**
	 * A d�finir par la couche m�tier.
	 * 
	 * @param uid
	 *            Universal ID de la t�che.
	 */
	@Override
	public String getUid() {
		return this.uid;
	}

	@Override
	public void setUid(final String uid) {
		this.uid = uid;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(final String description) {
		this.description = description;
	}

	public String getName() {
		return this.name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public String getPriority() {
		return this.priority;
	}

	public void setPriority(final String priority) {
		this.priority = priority;
	}

	public Date getExpectedEndDate() {
		return this.expectedEndDate;
	}

	public void setExpectedEndDate(final Date endDate) {
		this.expectedEndDate = endDate;
	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(final String status) {
		this.status = status;
	}

	public User getCreator() {
		return this.creator;
	}

	public void setCreator(final User user) {
		this.creator = user;
	}

	public List<User> getUsers() {
		if (this.users == null) {
			this.users = new ArrayList<User>();
		}
		return this.users;
	}

	public void setUsers(final List<User> users) {
		this.users = users;
	}

	@Override
	public String toString() {
		return "Name => " + this.getName() + ", Uid => " + this.getUid() + ", Id => " + this.getId();
	}

	public List<Comment> getComments() {
		if (this.comments == null) {
			this.comments = new ArrayList<Comment>();
		}
		return this.comments;
	}

	public void setComments(final List<Comment> comments) {
		this.comments = comments;
	}

	public Date getExpectedStartDate() {
		return this.expectedStartDate;
	}

	public void setExpectedStartDate(final Date expectedStartDate) {
		this.expectedStartDate = expectedStartDate;
	}

}